using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using MyFrame.Pool;
using TMPro;
using UnityEngine;
using Plugin.Tool;

public class PopUpTextFx : MonoBehaviour
{
    private TextMeshPro me;
    [SerializeField] private float durationTime;
    // private float durationTimer;
    [SerializeField] private float speed;
    [SerializeField] private float disappearSpeed;
    [SerializeField] private float fadeInTime;

    void Awake()
    {
        me = GetComponent<TextMeshPro>();
    }

    void OnEnable()
    {
        me.alpha = 1;
        StartCoroutine(StartMovement());
    }

    private IEnumerator StartMovement()
    {
        // 用对象池的代价，激活比设置位置快
        yield return null;
        transform.DOMove(transform.position + Vector3.up, durationTime / speed).SetEase(Ease.Linear)
            .OnComplete(() => StartFadeOut());
    }

    private void StartFadeOut()
    {
        me.DOFade(0, fadeInTime).OnComplete(() => PoolMgr.Instance.Release(gameObject));
    }

    // Update is called once per frame
    void Update()
    {
        // transform.position = Vector2.MoveTowards(transform.position, transform.position + Vector3.up, speed * Time.deltaTime);

        // durationTimer++;
        // if (durationTimer >= durationTime)
        // {
        //     me.alpha = me.alpha - fadeInTime * Time.deltaTime;

        //     if (me.color.a <= 50){
        //         speed  = disappearSpeed;
        //     }

        //         if (me.alpha <= 0)
        //         {
        //             Destroy(gameObject);
        //         }
        // }

    }
}
